package com.alinesno.cloud.common.web.base.bean;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alinesno.cloud.base.boot.entity.ManagerApplicationEntity;
import com.alinesno.cloud.base.boot.entity.ManagerCodeEntity;
import com.alinesno.cloud.base.boot.entity.ManagerDepartmentEntity;
import com.alinesno.cloud.base.boot.service.IManagerApplicationService;
import com.alinesno.cloud.base.boot.service.IManagerCodeService;
import com.alinesno.cloud.base.boot.service.IManagerDepartmentService;
import com.alinesno.cloud.common.facade.wrapper.RestWrapper;

/**
 * 页面服务接口，用于页面调用后台服务，比如代码转换，页面的常用值等，用于公共转换
 * @author WeiXiaoJin
 * @since 2020年1月11日 上午10:12:16
 */
@Component("pageHandle")
public class ThymeleafPageService extends PageService {

	private static final Logger log = LoggerFactory.getLogger(ThymeleafPageService.class) ; 

	@Autowired
	private IManagerApplicationService applicationService ; 
	
	@Autowired
	private IManagerDepartmentService departmentService ; 
	
	@Autowired
	private IManagerCodeService managerCodeService ; 

	private static final String EMPTY = "" ; 

	public String hello() {
		return "hello page service" ; 
	}
	
	/**
	 * 应用名称转换
	 * @return
	 */
	public String applicationLabel(String applicationId) {
		log.debug("application id = {}" , applicationId);
		ManagerApplicationEntity e = applicationService.findEntityById(applicationId) ; 
		if(e == null) {
			return EMPTY  ; 
		}
		return e.getApplicationName() ; 
	}
	

	/**
	 * 部门转换
	 * @param departmentId
	 * @return
	 */
	public String departmentLabel(String departmentId) {
		log.debug("departmentId = {}" , departmentId);
		ManagerDepartmentEntity e = departmentService.findEntityById(departmentId) ; 
		if(e == null) {
			return EMPTY  ; 
		}
		return e.getFullName() ; 
	}
	
	/**
	 * 代码转换
	 * @param value
	 * @param type
	 * @return
	 */
	public String directoryLabel(String value , String type) {
		log.debug("value = {} , type = {}" , value , type);
		
		return "代码名称" ; 
	}

	/**
	 * 列举出代码类型
	 * @param typeName
	 * @return 
	 */
	public List<ManagerCodeEntity> direcitoryList(String typeName) {
		RestWrapper restWrapper = new RestWrapper() ; 
		restWrapper.eq("codeTypeValue", typeName)
				   .eq("hasStatus", "0") ; 
		List<ManagerCodeEntity> list = managerCodeService.findAll(restWrapper) ; 
		return list ; 
	}
	
}
